package cn.dankal.flyaudio.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jeremyliao.liveeventbus.LiveEventBus;

import cn.dankal.basiclib.base.recyclerview.BaseRecyclerViewAdapter;
import cn.dankal.basiclib.base.recyclerview.BaseRecyclerViewHolder;
import cn.dankal.basiclib.pojo.ChildrenBean;
import cn.dankal.basiclib.util.image.PicUtils;
import cn.dankal.flyaudio.R;

/**
 * <pre>
 *     e-mail : junfeng.nie@duntech.com.cn
 *     time   : 28/7/2020
 *     desc   :
 *     version: cn.dankal.flyaudio.adapter
 *     Copyright: Copyright（c）2018
 *     Company:
 * </pre>
 *
 * @author niejunfeng
 */
public class CommentsDetailAdapter extends BaseRecyclerViewAdapter<ChildrenBean> {
    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_comments_detail;
    }

    @Override
    protected BaseRecyclerViewHolder getViewHolder(ViewGroup parent, View rootView, int viewType) {
        return new CommentsDetailAdapter.ViewHolder(rootView);
    }

    class ViewHolder extends BaseRecyclerViewHolder<ChildrenBean> {

        public ViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void onBindData(ChildrenBean data, int position) {
            ImageView itemIvAvatar = itemView.findViewById(R.id.iv_avatar);
            TextView itemTvContent = itemView.findViewById(R.id.item_tv_content);
            TextView itemTvName = itemView.findViewById(R.id.item_tv_name);
            TextView itemTvTime = itemView.findViewById(R.id.item_tv_time);
            ImageView item_iv_awesome = itemView.findViewById(R.id.item_iv_awesome);
            if ("true".equals(data.getiLike())) {
                item_iv_awesome.setImageResource(R.mipmap.ic_awesome);
            } else {
                item_iv_awesome.setImageResource(R.mipmap.ic_awesome_un);
            }

            setText(R.id.item_tv_awesome_num, data.getLikeCount());

            String avatar = "";
            String name = "";
            if (data.getCommentUser() != null) {
                avatar = data.getCommentUser().getAvatar();
                name = data.getCommentUser().getUsername();
            }
            PicUtils.loadAvatar(avatar, itemIvAvatar);
            itemTvContent.setText(data.getContent());
            itemTvName.setText(name);
            itemTvTime.setText(data.getCreatedDatetime());
            item_iv_awesome.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    LiveEventBus.get("Like", ChildrenBean.class).post(data);
                }
            });
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    LiveEventBus.get("ChildrenBean", ChildrenBean.class).post(data);
                }
            });
        }
    }
}
